home *** CD-ROM | disk | FTP | other *** search
- /* IOCTL.C --- p. 638 */
- #include <stdio.h>
- #include <io.h>
- #define RAW_BIT 0x20
- main(int argc, char **argv)
- {
- int raw_mode, handle = 1, /* standard output */
- cmd, argdx;
- if(argc <2)
- {
- printf("Usage: %s <COOKED or RAW>\n", argv[0]);
- exit(0);
- }
- if((strcmp(argv[1], "COOKED") == 0) ||
- (strcmp(argv[1], "cooked") == 0)) raw_mode = 0;
- else
- {
- if((strcmp(argv[1], "RAW") == 0) ||
- (strcmp(argv[1], "raw") == 0)) raw_mode = 1;
- else
- {
- printf("Unknown mode: %s\n", argv[1]);
- exit(0);
- }
- }
- /* Get device information (cmd = 0) using IOCTL */
- cmd = 0;
- ioctl(handle, cmd, &argdx);
- /* Set raw/cooked bit on or off depending on value
- * of variable "raw_mode" */
- argdx &= 0xff;
- if(raw_mode) argdx |= RAW_BIT;
- else argdx &= (-RAW_BIT);
- /* Call ioctl to set the raw/cooked mode bit */
- cmd = 1;
- ioctl(handle, cmd, &argdx);
- printf("Standard output is now in %s mode\n", argv[1]);
- printf("(If mode is RAW, remember to reset it to "
- "COOKED when you are done)");
- }